Public: Technology Reviews : Local Folders
This page last changed on Jul 20, 2009 by aunger.
Example folders:
LocationSYSTEM:
USER:
Possible Solutions
Windows Docs:Pre Vista Info: http://msdn.microsoft.com/en-us/library/bb762494%28VS.85%29.aspx Code examples(Some language syntax (e.g. class definition) ignored for brevity) Useful example code: On Mac (Application Support folder): import com.apple.eio.FileManager; String folder; // System folder folder = FileManager.findFolder(FileManager.kLocalDomain, FileManager.OSTypeToInt("asup")); // User folder folder = FileManager.findFolder(FileManager.kUserDomain, FileManager.OSTypeToInt("asup")); On Windows XP (Application Data folder): import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.PointerType; import com.sun.jna.win32.W32APITypeMapper; import com.sun.jna.win32.W32APIFunctionMapper; class HANDLE extends PointerType {} class HWND extends PointerType {} int CSIDL_COMMON_APPDATA = 35; //system folder int CSIDL_APPDATA = 26; //user folder int SHGFP_TYPE_CURRENT = 0; int SHGFP_TYPE_DEFAULT = 1; int MAX_PATH = 255; Map<String, Object> unicodeOptions = new HashMap<String, Object>(); unicodeOptions.put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); unicodeOptions.put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); interface Sh32Library extends Library { Sh32Library INSTANCE = (Sh32Library) Native.loadLibrary("shell32", Sh32Library.class, unicodeOptions); //shell32.dll int SHGetFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken, int dwFlags, char[] pszPath); } char[] chPath = new char[MAX_PATH+1]; int rcode = Sh32Library.INSTANCE.SHGetFolderPath(null, CSIDL_COMMON_APP_DATA, null, SHGFP_TYPE_CURRENT, chPath); // rcode == 0: success String path = new String(chPath); path = path.substring(0, path.indexOf(0)); //trim C string at null char File userFolder = new File(path); |
Document generated by Confluence on Jan 27, 2014 16:56 |